package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ken
 * Date: 2023-11-24
 * Time: 18:17
 */
public class AddOperation implements IOPeration {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = scanner.nextLine();
        System.out.println("请输入作者");
        String author = scanner.nextLine();
        System.out.println("请输入价格");
        int price = scanner.nextInt();
        String du = scanner.nextLine();  //吞多余的回车
        System.out.println("请输入书的类型");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        int current = bookList.getUsedSize();
        for(int i = 0 ; i <current; i++) {
            Book temp = bookList.getBook(i);
            if(temp.getName().equals(name)) {
                System.out.println("已经有这本书了，不能再放了！！");
                return;
            }
        }
        bookList.setbook(book);  //

        bookList.setUsedSize(current+1);  //修改UsedSize
    }
}
